package com.chenfan.mcn.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chenfan.mcn.clients.baseinfo.BaseCustomer;
import com.chenfan.mcn.dao.IncomeContractMapper;
import com.chenfan.common.extension.mybatisplus.enhanced.EnhancedService;
import com.chenfan.mcn.model.*;
import com.chenfan.mcn.model.dto.*;
import com.chenfan.mcn.model.rpc.ChargeClearCallback;
import com.chenfan.mcn.model.vo.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


/**
 * @author tangwei
 * Date:     2021/1/20 10:42
 * Description: 收入合同
 */
public interface IncomeContractService extends EnhancedService<IncomeContractMapper, IncomeContract> {

    /**
     * 新增收入合同
     *
     * @param incomeContractAddDTO
     * @return Integer
     */
    Long addIncomeContract(IncomeContractAddDTO incomeContractAddDTO);

    /**
     * 修改收入合同
     *
     * @param incomeContractAddDTO
     * @return Integer
     */
    Long updateIncomeContract(IncomeContractAddDTO incomeContractAddDTO);

    /**
     * 收入合同详情
     *
     * @param id
     * @return IncomeContractDetailVO
     */
    IncomeContractDetailVO incomeContractDetail(Long id);

    /**
     * 搜索收入合同分页
     *
     * @param mcnPage
     * @param incomeContractSearchDTO
     * @return IncomeContractListVO
     */
    Page<IncomeContractListVO> getContractPage(McnPage<IncomeContractListVO> mcnPage, IncomeContractSearchDTO incomeContractSearchDTO);

    /**
     * 搜索收入合同列表
     *
     * @param incomeContractSearchDTO
     * @return List<BasicContractVO>
     */
    List<BasicContractVO> getContractList(IncomeContractSearchDTO incomeContractSearchDTO);

    /**
     * 收入合同导出
     *
     * @param incomeContractSearchDTO
     * @return List<IncomeContractExportVO>
     */
    List<IncomeContractExportVO> exportContract(IncomeContractSearchDTO incomeContractSearchDTO);

    /**
     * 框架合同导出
     *
     * @param incomeContractSearchDTO
     * @return List<LiveContractExportVO>
     */
    List<LiveContractExportVO> exportLiveContract(IncomeContractSearchDTO incomeContractSearchDTO);


    /**
     * 导出收入合同补充协议
     *
     * @param incomeContractSearchDTO
     * @return List<IncomeContractAgreementExportVO>
     */
    List<IncomeContractAgreementExportVO> exportAgreement(IncomeContractSearchDTO incomeContractSearchDTO);

    /**
     * 修改收入合同-单据状态
     *
     * @param incomeContractId
     * @param approvalStatus
     * @return
     */
    boolean changeStatus(Long incomeContractId, Integer approvalStatus);

    /**
     * 获取收入合同编号
     *
     * @return {@link List<String>}
     */
    List<String> getIncomeContractCode();

    /**
     * 根据合同编号获取收入合同
     *
     * @param contractCode
     * @param tenantId
     * @return IncomeContract
     */
    IncomeContract getByCode(String contractCode, Long tenantId);

    /**
     * 根据客户id获取收入合同编号
     *
     * @param customerId {@link Long}
     * @return {@link List}
     */
    List<String> getIncomeCode(Long customerId);

    /**
     * 客户关联的合同、执行单信息
     *
     * @param customerId
     * @param mcnPage
     * @return CustomerContractInfoVO {@link CustomerContractInfoVO}
     */
    Page<CusIncomeContractVO> getCusContractInfo(McnPage<CusIncomeContractVO> mcnPage, Long customerId);

    /**
     * 核销后回款回调
     *
     * @param dto          回款报文
     * @param incomeContract 收入合同
     * @param isOfflineCommission 是否是线下佣金
     * @return
     */
    boolean updatePayback(ChargeClearCallback dto, IncomeContract incomeContract, boolean isOfflineCommission);

    /**
     * 获取客户档案金额
     *
     * @param customerId {@link Long}
     * @return {@link CustomerFileAmount}
     */
    CustomerFileAmount getCustomerFileAmount(Long customerId);

    /**
     * 获取列表合计金额（合同金额、回款金额）
     *
     * @param dto
     * @return IncomeAmountSumVO {@link IncomeAmountSumVO}
     */
    IncomeAmountSumVO getSumAmount(IncomeContractSearchDTO dto);

    /**
     * 关联合同
     *
     * @param billingId
     * @return
     */
    List<Long> getRelatedIncomeContract(Long billingId);

    /**
     * 根据客户名称获取收入合同编号
     *
     * @param customerId {@link Long}
     * @return {@link List}
     */
    List<IncomeContract> getIncomeCodesByCustomerId(Long customerId);

    /**
     * 获取收入合同金额
     *
     * @param incomeCode {@link String}
     * @return {@link BigDecimal}
     */
    BigDecimal getIncomeContractAmount(String incomeCode);

    /**
     * 保存执行反馈
     *
     * @param excutionOrder
     * @param feedbackInsertList
     */
    void saveFeedBack(ContractExcutionOrder excutionOrder, List<ExcuteFeedback> feedbackInsertList);

    /**
     * 保存计算分成
     *
     * @param excutionOrder
     * @param customerId
     * @param calculationDevided
     * @param discountId
     * @param customerMap
     * @return
     */
    CalculationDevided saveCalculationDevided(Long customerId, Long discountId, CalculationDevided calculationDevided, Map<Long, BaseCustomer> customerMap, ContractExcutionOrder excutionOrder);

    /**
     * 刷计算分成数据
     *
     * @return {@link Integer}
     */
    boolean refreshCalculationDevided();

    /**
     * 获取收入合同的预估成本
     *
     * @param incomeContractId
     * @return {@link BigDecimal}
     */
    BigDecimal getExpectedAmount(Long incomeContractId);

    /**
     * 更新收入合同预估成本
     *
     * @param incomeContractId
     * @return
     */
    boolean updateExpectedAmount(Long incomeContractId);

    /**
     * 刷所有历史数据的预估成本
     */
    void setExpectedAmount();

    /**
     * 刷单个收入合同的预估成本
     *
     * @param incomeContractId
     */
    void setSingleExpectedAmount(Long incomeContractId);

    /**
     * 校验商务确认合同金额
     *
     * @param id {@link Long}
     * @return {@link List<ContractExcutionOrder>}
     */
    List<ContractExcutionOrder> confirmedAmount(Long id);

    /**
     * 根据收入合同编号获取金额
     *
     * @param incomeCodes {@link List<String>}
     * @return {@link BigDecimal}
     */
    BigDecimal getAmountOfMoney(List<String> incomeCodes);

    /**
     * 法务审批
     * @param dto
     * @return
     */
    boolean legalApproval(IncomeContractLegalApprovalDTO dto);

    /**
     * 分页查询可关联的收入合同
     * @param queryContractDTO
     * @return
     */
    Page<AnnualRebateIncomeContractListVO> queryIncomeContractByPage(AnnualRebateQueryContractDTO queryContractDTO);

    /**
     * 查询待认领的直播合同
     * @param dto
     * @return
     */
    Page<LiveContractSelectVO> queryUnClaimLiveContract(LiveContractQueryDto dto);

    /**
     * 修改业绩共享人
     * @param dto
     * @return
     */
    Long updatePerformanceSharer(PerformanceSharerUpdateDTO dto);

    /**
     * 重新生成收入合同费
     * @param incomeContractId
     * @return
     */
    Long regenerateIncomeFee(Long incomeContractId);

    /**
     * 重复录入执行单提醒
     * @param approvalStatus
     * @param excutionOrders
     */
    void remindDuplicateEntry(Integer approvalStatus, List<ContractExcutionOrder> excutionOrders);

    /**
     * 直播提成发放
     * @param id 收入合同id
     */
    Boolean distributeLiveCommission(Long id);
}